/**
 * Plan name: Login and register
 * Product: Seam Portal
 */
package test;

import core.SeleneseTestCaseEx;

/**
 * @author Roman I.
 *
 */
public class LoginAndRegistration extends SeleneseTestCaseEx {
	
	public LoginAndRegistration(String name) {
		super(name);
	}

	public void setUp() {
		if (configureTest) {
			tc.setEnv("_testtitle", "Login and Register");
			super.setUp();
		}	
	}
	
	/**
	 * 39 Register-Register a new user with valid information 
	 */
    public void testRegisterUserValidData() {
	
		repEng.newStep("39", "Register User(valid data)");
			
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Fill in all fields with valid information
		action.typeByContainsId("email", u.getNewEmail(true));
		action.typeByContainsId("confirmEmail", u.getNewEmail(false));
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test1234");
		//action.typeByContainsId("verifyCaptcha", "");
		
		//4. Click Register button
		action.click("//input[@value='Register']");
		
		//A new user should be created successfully
		check.checkTextOnPage("Registered Successfully!");
	}
	
	/**
	 * 40 Register-Attempt to register a new user with invalid email account
	 */
    public void testRegisterUserInvalidEmail() {
		repEng.newStep("40", "Register User(invalid email)");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Fill in an invalid email to email field
		action.typeByContainsId("email", "test.com");
		action.typeByContainsId("confirmEmail", "test.com");
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test1234");
		//action.typeByContainsId("verifyCaptcha", ""); 
		
		//4. Click Register button
		action.click("//input[@value='Register']");
		
		//Should get message said that the email address is not valid, and no new user created
		check.checkWarningUserCreation("The email you entered is not a valid");
	}
	
	/**
	 * 41 Register-Attempt to register a new user who is already existed
	 */
	public void testRegisterAsExistUser() {
		repEng.newStep("41", "Register User(Existing User)");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Enter an email address which already be used
		action.typeByContainsId("email", "test@mail.com");  
		action.typeByContainsId("confirmEmail", "test@mail.com");
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test1234");  //This account is exist - 31 05 2009
		// action.typeByContainsId("verifyCaptcha", ""); 
		
		//4. Click Register
		action.click("//input[@value='Register']");
		
		// Get error message said that this email address already be used
		check.checkWarningUserCreation("This email is already used by another user"); 
	}

	/**
	 * 42 Register-Attempt to register a user when Email and Confirm Email does not match
	 */
	public void testRegisterWithDifferentEmail() {
		repEng.newStep("42", "Register User(different email)");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3.Fill in Email and Confirm Email with different address
		action.typeByContainsId("email", u.getNewEmail(true));	
		action.typeByContainsId("confirmEmail", "test@google.com");
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test1234");
		//action.typeByContainsId("verifyCaptcha", ""); 
		
		//4. Click Register
		action.click("//input[@value='Register']");
		
		//Get error message said that the Email and Confirm Email does not match
		check.checkWarningUserCreation("Email and Confirm Email fields should have the same value.");
	}
	
	/**
	 * 43 Register-Attempt to register a new account when Password and Confirm Password does not match
	 */
	public void testRegisterWithDifferentPass() {
		repEng.newStep("43", "Register User(different password)");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Enter Password and Confirm Password with different ones
		action.typeByContainsId("email", u.getNewEmail(true));
		action.typeByContainsId("confirmEmail", u.getNewEmail(false));
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test4321");
		//action.typeByContainsId("verifyCaptcha", ""); 
		
		//4. Click Register
		action.click("//input[@value='Register']");
		
		//Get message said that the Password and Confirm Password does not match and no new account was created
		check.checkWarningUserCreation("Password and Confirm Password fields should have the same value."); 
	}
	
	/**
	 * 44 Register-Attempt to Register a new user with entering incorrect response
	 */
	public void testRegisterWithIncorrectCaptcha() {    //Captcha was deleted from site
		repEng.newStep("44", "Register User(inccorrect captcha)");
		action.difficultToImplement("Verify captcha");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		//2. Click Register an Account
		//3. Enter Email/Confirm Email/Password/Confirm Password
		//4. Fill in'Solve the operation below' with incorrect response
		//5. Click Register
		//Get error message and no new account was created
	}
	
	/**
	 * 45 Register-Attempt to register a new account with keeping all required fields blank
	 */
	public void testRegisterWithoutData() {
		repEng.newStep("45", "Register User(blank fields)");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Do not fill in any fields and click Register button
		action.click("//input[@value='Register']");
		
		//Get error message and no new account was created
		check.checkWarningUserCreation("Validation Error: Value is required."); 
	}
	
	/**
	 * 46 Forgot Password-Enter Email and then click Forgot Password
	 */
	public void testForgotPassWithValidEmail() {
		repEng.newStep("46", "Forgot Password (valid email)");
		
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Enter valid email and click Forgot Password
		action.typeByContainsId("name", "test@mail.com");
		action.clickNoWait("link=exact:Forgot Password?"); //TODO change to action.click after fixing
		
		//3. Check the email
		action.difficultToImplement("Check the email");
		//action.navigateToEmail("www.mail.com", "test1test2test@mail.com", "test1234"); 
		
		//The password should be sent to this email account
		check.difficultToImplement("The password should be sent to this email account");
	}
	
	/**
	 * 47 Forgot Password- Enter an invalid or non-existed email and then click Forgot password
	 */
	public void testForgotPassWithInvalidEmail() {
		repEng.newStep("47","Forgot Password (Invalid email)");
		
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Enter an invalid or non-existed email
		action.typeByContainsId("name", "test.com");
		
		//3. Click Forgot Password
		action.clickNoWait("link=exact:Forgot Password?"); //TODO change to action.click after fixing
		
		//Get message said that the email is not valid
		check.checkTextOnPage("email is not valid"); //TODO needs to change
	}
	
	/**
	 * 48 Login-Login magnet portal with valid email and password
	 */
	public void testLoginWithValidData() {
		repEng.newStep("48", "Login (valid data)");
		
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
						
		//2. Fill in all fields with valid information
		action.typeByContainsId("name", "test@mail.com");
		action.typeByContainsId("password", "test123");
				
		//3. Click Login button
		action.click("//input[@value='Login']");
		
		//Login should be successfully
		check.verifyTitle("Welcome"); 
	}
	
	/**
	 * 49 Login- Attempt to use invalid or non-existed email to login
	 */
	public void testLoginWithInvalidEmail() {
		repEng.newStep("49", "Login (invalid email)");
		
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Fill in an invalid email to email field
		// action.typeByContainsId("email", "test.com");		
		action.typeByContainsId("name", u.getNewEmail(true));
		action.typeByContainsId("password", "test1234");
				
		//3. Click Login button
		action.click("//input[@value='Login']");
		
		//Should get message said that the email address is not valid, and no login
		check.checkWarningUserCreation("Login failed"); 
	}
	
	/**
	 * 50 Login-Attempt to login with invalid password
	 */
	public void testLoginWithInvalidPass() {
		repEng.newStep("50","Login (invalid pass)");
		
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Fill invalid password to password field
		action.typeByContainsId("name", "test@mail.com");
		action.typeByContainsId("password", "test4321");
		
		//3. Click Login button
		action.click("//input[@value='Login']");
		
		//Should get message said that the password is not valid, and no login
		check.checkWarningUserCreation("Login failed");
	}
	
	/**
	 * 64 Register- Attempt to register a new user with keeping 'Solve the operation below' blank
	 */
	public void testRegisterWithSolveBlank() { 
		repEng.newStep("64", "Register User ('Solve the operation below' blank)");
		action.difficultToImplement("Verify captcha");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		//2. Click Register an Account
		//3. Fill in all fields with valid information
		//4. Keep 'Solve the operation below' blank
		//5. Click Register button
		//Get message said it's required field
	}
	
	/**
	 * 114 Register-Check the link of click here to login
	 */
	public void testRegisterCheckLinkclickHere() {
		repEng.newStep("114", "Check the link of click here to login");
		
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Fill in all fields with valid information
		String email = u.getNewEmail(true);
		action.typeByContainsId("email", email);
		action.typeByContainsId("confirmEmail", email);
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test1234");
		//action.typeByContainsId("verifyCaptcha", ""); 
		
		//4. Click Register button
		action.click("//input[@value='Register']");
		
		//5. Click the link of Click here to login 
		action.click("link=Click here to login");
		
		//6. Login with newly created user. Fill in all fields with valid information
		action.typeByContainsId("email", email);
		action.typeByContainsId("password", "test1234");
		
		//7. Click Login button
		action.click("//input[@value='Login']");
		
		//Login should be successfully
		check.checkTextOnPage("Welcome"); 		
	}
	
	/**
	 * 224 Register - User should receive an email reminder after registering an account.
	 */
	public void testEmailReminderAfterRegistering() {
		repEng.newStep("224", "Email reminder after registering");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Click Register an Account
		action.click("link=Register an Account.");
		
		//3. Fill in all fields with valid information
		action.typeByContainsId("email", "test@mail.com");
		action.typeByContainsId("confirmEmail", "test@mail.com");
		action.typeByContainsId("password", "test1234");
		action.typeByContainsId("confirmPassword", "test1234");
		//action.typeByContainsId("verifyCaptcha", ""); 
		
		//4. Click Register button
		action.click("//input[@value='Register']");
		
		//5. Check the email
		action.navigateToEmail("www.mail.com", "test@mail.com", "test123");
		
		//User should receive an email reminder after registering an account.
		check.checkTextEmail("reminder");
		check.difficultToImplement("User should receive an email reminder after registering an account");
	}
	
	/**
	 * 225 Register-User should receive an email reminder after clicking "Forgot Password" link
	 */
	public void testEmailReminderAfterFogotPass() {
		repEng.newStep("225", "Forgot Password(valid email)");
		//1. Open http://hobbes.ontometrics.com/magnetportal/ in IE
		action.launchBrowser();
		action.openURL(tc.getEnv("mainurl") + "magnetportal/");
		
		//2. Enter existent email and click Forgot Password
		action.typeByContainsId("name", "test@mail.com");
		action.clickNoWait("link=exact:Forgot Password?"); //TODO change to action.click after fixing
		
		//3. Check the email
		action.difficultToImplement("Check the email");
		
		//The password should be sent to this email account
		check.difficultToImplement("The password should be sent to this email account");
		//check.checkTextEmail("password"); //TODO needs for change
	}
	

}
